<?php

/**
 * \file
 * Interface `AuthenticationObject`.
 */

namespace pilar\AuthenticationManager /* \cond */ ; /* \endcond */
{

abstract class AbstractAuthenticationObject
         extends \pilar\Configurables\Configurable
         implements AuthenticationObject {


/**
 * Page de redirection.
 */
protected $_authenticationPageUrl = '';


/**
 * Entité d'authentification.
 */
protected $_authEntity = null;


/**
 * Membre d'entité de login.
 */
protected $_loginMemberName = '';


/**
 * Membre d'entité de mot de passe.
 */
protected $_passwordMemberName = '';


/**
 * Gestionnaire de session.
 */
protected $_sessionManager = null;


protected function loadDefaultParams() {
	parent::loadDefaultParams();
	
	$this->defineParams(array(
		'authenticationObjectParams' => array(
			'authEntity' => null,
			'loginMemberName' => '',
			'passwordMemberName' => ''
		),
		'sessionManager' => null
	));
}


/**
 * Encode le mot de passe avec la méthode choisie.
 *
 * \param $pwd Mot de passe à encoder.
 * \return Mot de passe encodée.
 * \since 06/07/2009
 */
public function encodePassword($pwd) {
	switch(PILAR_ENCRYPTION_METHOD) {
		case 'MD5' :
			return md5($pwd);
		default :
			return $pwd;
	}
}


protected function initialize() {
	parent::initialize();

	$this->_sessionManager = $this->param('sessionManager');
	
	$authEntityParams = $this->param('authenticationObjectParams');
	$this->_authEntity = $authEntityParams['authEntity'];
	$this->_loginMemberName = $authEntityParams['loginMemberName'];
	$this->_passwordMemberName = $authEntityParams['passwordMemberName'];
	$this->_authenticationPageUrl = PILAR_LOGIN_PAGE_URL;
}


} // Interface.

} // Namespace.
